<!-- 预警管理 -->
<template>
  <div>
    <ZgDialog v-model="visible" width="60%" :title="title">
      <ZgNewPage
        ref="page"
        :showInlineBtn="false"
        :uniqueName="uniqueName"
        :pageOpt="pageOpt"
        :headers="headers"
        :conditions="conditions"
        :scrollX="1000"
        @search="onSearch"
        @filter="onFilter"
        @header="mergeHeader"
        @admin="toAdmin"
      >
        <template slot="columns">
          <a-table-column
            v-for="(h,i) in headers"
            :key="`column${i}`"
            :width="h.width===0 ? 'auto' : h.width"
            align="center"
            :title="h.label">
            <template slot-scope="record">
              <template>{{ record[h.code] }}</template>
            </template>
          </a-table-column>
        </template>
        <template slot="thMode" slot-scope="scope">
          <a-row :gutter="10">
            <a-col :span="4" v-for="t in scope.list" :key="`thMode_${t.id}`">
              <a-card class="mb10">
                <div class="wfull h100 scroll">
                  {{ t }}
                </div>
              </a-card>
            </a-col>
          </a-row>
        </template>
      </ZgNewPage>
    </ZgDialog>
  </div>
</template>
<script>
export default {
  components: {
  },
  data () {
    return {
      pageTitle: '产品类型',
      uniqueName: 'test',
      visible: false,
      title: '关联产品',
      pageOpt: {
        showConditionBtn: false,
        showHeaderConfig: false,
        showAttachBtn: false,
        showPageTitle: false
      },
      conditions: [],
      headers: [
        { code: 'A', label: '金融机构', isShow: true, sort: 0 },
        { code: 'B', label: '产品名称', isShow: true, sort: 0 },
        { code: 'C', label: '授信方式', isShow: true, sort: 0 }
      ]
    }
  },
  methods: {
    open () {
      this.visible = true
    },
    search () {
      this.$refs.page.search()
    },
    onSearch (param) {
      const diyHeaders = localStorage.getItem(this.currentUser.username + '_diyHeader_' + this.uniqueName)
      if (diyHeaders) {
        this.mergeHeader(JSON.parse(diyHeaders))
      }
      // 加载表头
      const list = [
        { key: '1', id: '1', A: '1111', B: '2222', C: '3333' },
        { key: '2', id: '2', A: '1111', B: '2222', C: '3333' }
      ]
      this.$refs.page.endSearch({
        total: list.length,
        list: list
      })
    },
    onFilter (f, param) {
    },
    toAdd () {
      alert('新增数据')
       //   this.$refs.add.open()
    },
    toAdmin (param) {
      if (param.key === 1) {
        this.$refs.update.open({}, 'details')
      } else if (param.key === 2) {
        this.$refs.update.open()
      } else if (param.key === 3) {
         this.confirm(
          () => {
            // this.$http.post('/zg-system/attach/del', [param.obj.id], () => {
            //   this.$refs.page.search()
            // })
          },
        '确定要删除这条数据么')
      } else if (param.key === 4) {
      }
    },
    mergeHeader (newHeaders) {
      if (!newHeaders) {
        return
      }
      this.headers = newHeaders.filter(t => {
        return t.isShow
      }).sort((a, b) => {
        return a.sort - b.sort
      })
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
